package com.kqb.config;

import com.kqb.autoconfigure.TokenInterceptorProperties;
import com.kqb.interceptor.TokenInterceptor;
import com.kqb.token.TokenTemplate;
import org.springframework.web.servlet.config.annotation.InterceptorRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;

/**
 * @author 杉果树皮
 * @date 2025/2/12 19:53
 * @description:
 */
public class TokenWebMvcConfig implements WebMvcConfigurer {
    private TokenTemplate tokenTemplate;

    private TokenInterceptorProperties tokenInterceptorProperties;

    public TokenWebMvcConfig(TokenTemplate tokenTemplate, TokenInterceptorProperties tokenInterceptorProperties) {
        this.tokenTemplate = tokenTemplate;
        this.tokenInterceptorProperties = tokenInterceptorProperties;
    }

    @Override
    public void addInterceptors(InterceptorRegistry registry) {
        registry.addInterceptor(new TokenInterceptor(tokenTemplate))
                .addPathPatterns(tokenInterceptorProperties.getPathPatterns()).excludePathPatterns(tokenInterceptorProperties.getExcludePathPatterns());
    }
}
